package edu.nf.utils.handler;

import edu.nf.utils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

abstract class AbstractListHandler<T> implements ResultSetHandler<List<T>> {


    public List<T> handle(ResultSet rs) throws SQLException {
        ResultSetMetaData md = rs.getMetaData();
        List<T> list = new ArrayList<T>();
        for (int i = 0; i < md.getColumnCount(); i++) {
            list.add(getRow(rs));
        }
        return list;
    }

    protected abstract T getRow(ResultSet rs) throws SQLException;
}
